<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Message extends MY_Controller {
	
	function __construct(){
		parent::__construct();
		$user = $this->session->userdata('rsh_user');
		if(!isset($user['user_id'])){
			$str = $_SERVER['REQUEST_URI'];
			$this->js->go('/login.html');
		}elseif(!$user['user_id']){
			$this->js->go('/login.html');
		}
	}
	
	function index(){
		
	}
	
	// 站内信列表
	function zhs_received(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && intval($user['user_id']) > 0){
			$page = intval($this->input->get('per_page'));;
			$user_id = $user['user_id'];
			$data = array();
			$data = $this->get_user_info('','received','invite');
			$this->load->model('Message_model', 'message');
			$msg = $this->message->receive_box($user_id,$page);
			//$no_read_count = $this->message->no_read_count($user_id);
			//var_dump($msg);exit;
			
			$this->load->library('pagination');
			$config['base_url'] = '/message/zhs_received.html?';
			$config['total_rows'] = $msg['count'];
			$config['per_page'] = USER_CENTER_PAGE_SIZE;
			$this->pagination->initialize($config);
			
			$data['tab'] = 'user';
			$data['sub'] = 'user';
			$data['user_sub'] = 'user_mail';
			$data['list'] = $msg['list'];
			$data['msg_count'] = $msg['count'];
			$data['title'] = "站内信".' - '.CON_KEYWORDS;
			$data['sub_1'] = "我的账户";
			$data['sub_1_href'] = "/user/zhs_info/contact.html";
			$data['sub_2'] = "站内信";
			$data['sub_2_href'] = "/message/zhs_received.html";
			$this->load->view('user/zhs_user_message_list',$data);
		}else{
			header('Location: /login/index/index.html');
		}
	}
	
	function sendbox(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && intval($user['user_id']) > 0){
			$page = intval($this->input->get('per_page'));;
			$user_id = $user['user_id'];
			$data = array();
			$data = $this->get_user_info('','received','invite');
			
			$this->load->model('Message_model', 'message');
			$msg = $this->message->send_box($user_id,$page);
			$this->load->library('pagination');
			$config['base_url'] = '/message/received.html?';
			$config['total_rows'] = $msg['count'];
			$config['per_page'] = USER_CENTER_PAGE_SIZE;
			//$config['num_links'] = 1;
			$this->pagination->initialize($config);
			$data['list'] = $msg['list'];
			//$data['total'] = $msg['count'];
			$data['title'] = "站内信".' - '.CON_KEYWORDS;
			$this->load->view('user/user_message_sendbox',$data);
		}else{
			header('Location: /login/index/index.html');
		}
	}
	
	/*function doread(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && intval($user['user_id']) > 0){
			$user_id = $user['user_id'];
			$ids = $this->input->post('id');
			$fstatus = $this->input->post('status');
			$fstatus = $fstatus ? 1 : 0;
			if(!isset($ids[0])){
				$ret['msg'] = '请先选择';
				echo json_encode($ret);
				exit;
			}
			foreach($ids as $k=>$v){
				$ids[$k] = intval($v);
			}
			
			$this->load->model('Message_model', 'message');
			$this->message->read_message($ids,$user_id,$fstatus);
			$ret = array(
				'msg' => '',
				'data' => array(
					'url' => '',
				),
			);
			echo json_encode($ret);
			
		}else{
			header('Location: /login/index/index.html');
		}
	}*/
	
	
	
	function dodel(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && intval($user['user_id']) > 0){
			$user_id = $user['user_id'];
			$ids = $this->input->post('id');
			$is_receive = $this->input->post('is_receive');
			
			if(!$ids){
				$ret['msg'] = '请先选择';
				echo json_encode($ret);
				exit;
			}
			if(is_array($ids)){
				foreach($ids as $k=>$v){
					$ids[$k] = intval($v);
				}
			}else{
				$ids = array(intval($ids));
			}
			
				
			$this->load->model('Message_model', 'message');
			$this->message->del_message($ids,$user_id,$is_receive);
			$ret = array(
				'msg' => '',
				'data' => array(
					'url' => '',
				),
			);
			echo json_encode($ret);
			
		}else{
			header('Location: /login/index/index.html');
		}
	}
	
	function zhs_view($id){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && intval($user['user_id']) > 0){
			$data = $this->get_user_info('','received','invite');
			
			//$data = array('msg'=>'');
			$data['msg'] = '';
			
			$user_id = $user['user_id'];
			$id = intval($id);
			$this->load->model('Message_model', 'message');
			$info = $this->message->get_one(array('id'=>$id));
			if($info){
				if($info['sent_user']==$user_id){
					$this->load->model('User_model', 'user');
					$other_uid = $info['receive_user'] ? $info['receive_user'] : 1;
					$other_user = $this->user->get_by_uid($other_uid);
					$info['receive_username'] = $other_user['username'];
					$info['is_receive'] = 0;
				}elseif($info['receive_user']==$user_id){
					$this->load->model('User_model', 'user');
					$this->message->read_message(array($id),$user_id,1);
					$other_uid = $info['sent_user'] ? $info['sent_user'] : 1;
					$other_user = $this->user->get_by_uid($other_uid);
					$info['sent_username'] = $other_user['username'];
					$info['is_receive'] = 1;
				}else{
					//echo "非法操作";
					$data['msg'] = '非法操作';
					$data['url'] = '/message/received/index.html';
				}
			}else{
				$data['msg'] = '非法操作';
				$data['url'] = '/message/received/index.html';
			}
			
			
			$data['info'] = $info;
			$data['title'] = "站内信".' - '.CON_KEYWORDS;
			$data['sub_1'] = "我的账户";
			$data['sub_1_href'] = "/user/zhs_info/contact.html";
			$data['sub_2'] = "站内信";
			$data['sub_2_href'] = "/message/zhs_received.html";
			$data['tab'] = 'user';
			$data['user_sub'] = 'user_mail';
			$this->load->view('user/zhs_user_message_view',$data);
			
		}else{
			header('Location: /login');
		}
	}
}
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Message extends MY_Controller {
    
	function __construct(){
		parent::__construct();
		$user = $this->session->userdata('rsh_user');
		if(!isset($user['user_id'])){
			$str = $_SERVER['REQUEST_URI'];
			$this->js->go('/login.html');
		}elseif(!$user['user_id']){
			$this->js->go('/login.html');
		}
	}
	
	function index(){
		
	}
	
	// 站内信列表
	function zhs_received(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && intval($user['user_id']) > 0){
			$page = intval($this->input->get('per_page'));;
			$user_id = $user['user_id'];
			$data = array();
			$data = $this->get_user_info('','received','invite');
			$this->load->model('Message_model', 'message');
			$msg = $this->message->receive_box($user_id,$page);
			//$no_read_count = $this->message->no_read_count($user_id);
			//var_dump($msg);exit;
			
			$this->load->library('pagination');
			$config['base_url'] = '/message/zhs_received.html?';
			$config['total_rows'] = $msg['count'];
			$config['per_page'] = USER_CENTER_PAGE_SIZE;
			$this->pagination->initialize($config);
			
			$data['tab'] = 'user';
			$data['sub'] = 'user';
			$data['user_sub'] = 'user_mail';
			$data['list'] = $msg['list'];
			$data['msg_count'] = $msg['count'];
			$data['title'] = "站内信".' - '.CON_KEYWORDS;
			$data['sub_1'] = "我的账户";
			$data['sub_1_href'] = "/user/zhs_info/contact.html";
			$data['sub_2'] = "站内信";
			$data['sub_2_href'] = "/message/zhs_received.html";
			$this->load->view('user/zhs_user_message_list',$data);
		}else{
			header('Location: /login/index/index.html');
		}
	}
	
	function sendbox(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && intval($user['user_id']) > 0){
			$page = intval($this->input->get('per_page'));;
			$user_id = $user['user_id'];
			$data = array();
			$data = $this->get_user_info('','received','invite');
			
			$this->load->model('Message_model', 'message');
			$msg = $this->message->send_box($user_id,$page);
			$this->load->library('pagination');
			$config['base_url'] = '/message/received.html?';
			$config['total_rows'] = $msg['count'];
			$config['per_page'] = USER_CENTER_PAGE_SIZE;
			//$config['num_links'] = 1;
			$this->pagination->initialize($config);
			$data['list'] = $msg['list'];
			//$data['total'] = $msg['count'];
			$data['title'] = "站内信".' - '.CON_KEYWORDS;
			$this->load->view('user/user_message_sendbox',$data);
		}else{
			header('Location: /login/index/index.html');
		}
	}
	
	/*function doread(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && intval($user['user_id']) > 0){
			$user_id = $user['user_id'];
			$ids = $this->input->post('id');
			$fstatus = $this->input->post('status');
			$fstatus = $fstatus ? 1 : 0;
			if(!isset($ids[0])){
				$ret['msg'] = '请先选择';
				echo json_encode($ret);
				exit;
			}
			foreach($ids as $k=>$v){
				$ids[$k] = intval($v);
			}
			
			$this->load->model('Message_model', 'message');
			$this->message->read_message($ids,$user_id,$fstatus);
			$ret = array(
				'msg' => '',
				'data' => array(
					'url' => '',
				),
			);
			echo json_encode($ret);
			
		}else{
			header('Location: /login/index/index.html');
		}
	}*/
	
	
	
	function dodel(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && intval($user['user_id']) > 0){
			$user_id = $user['user_id'];
			$ids = $this->input->post('id');
			$is_receive = $this->input->post('is_receive');
			
			if(!$ids){
				$ret['msg'] = '请先选择';
				echo json_encode($ret);
				exit;
			}
			if(is_array($ids)){
				foreach($ids as $k=>$v){
					$ids[$k] = intval($v);
				}
			}else{
				$ids = array(intval($ids));
			}
			
				
			$this->load->model('Message_model', 'message');
			$this->message->del_message($ids,$user_id,$is_receive);
			$ret = array(
				'msg' => '',
				'data' => array(
					'url' => '',
				),
			);
			echo json_encode($ret);
			
		}else{
			header('Location: /login/index/index.html');
		}
	}
	
	function zhs_view($id){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && intval($user['user_id']) > 0){
			$data = $this->get_user_info('','received','invite');
			
			//$data = array('msg'=>'');
			$data['msg'] = '';
			
			$user_id = $user['user_id'];
			$id = intval($id);
			$this->load->model('Message_model', 'message');
			$info = $this->message->get_one(array('id'=>$id));
			if($info){
				if($info['sent_user']==$user_id){
					$this->load->model('User_model', 'user');
					$other_uid = $info['receive_user'] ? $info['receive_user'] : 1;
					$other_user = $this->user->get_by_uid($other_uid);
					$info['receive_username'] = $other_user['username'];
					$info['is_receive'] = 0;
				}elseif($info['receive_user']==$user_id){
					$this->load->model('User_model', 'user');
					$this->message->read_message(array($id),$user_id,1);
					$other_uid = $info['sent_user'] ? $info['sent_user'] : 1;
					$other_user = $this->user->get_by_uid($other_uid);
					$info['sent_username'] = $other_user['username'];
					$info['is_receive'] = 1;
				}else{
					//echo "非法操作";
					$data['msg'] = '非法操作';
					$data['url'] = '/message/received/index.html';
				}
			}else{
				$data['msg'] = '非法操作';
				$data['url'] = '/message/received/index.html';
			}
			
			
			$data['info'] = $info;
			$data['title'] = "站内信".' - '.CON_KEYWORDS;
			$data['sub_1'] = "我的账户";
			$data['sub_1_href'] = "/user/zhs_info/contact.html";
			$data['sub_2'] = "站内信";
			$data['sub_2_href'] = "/message/zhs_received.html";
			$data['tab'] = 'user';
			$data['user_sub'] = 'user_mail';
			$this->load->view('user/zhs_user_message_view',$data);
			
		}else{
			header('Location: /login');
		}
	}
}
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
